# -*- coding:utf-8 -*-
"""
@Time   : 2019/11/20 23:05
@Author : LeeCQ

通过url获取 种子和链接
"""

import requests
import re
import sys

from HTTP.Downloader1024.common.headers import request_head_urls as head
from HTTP.Downloader1024.common.functions import *


def get_magnet_torrent(url, _header):
    _header['Referer'] = url
    _host = url[:url.find('torrent')]

    response_header, page = getHtml(urls)

    magnet = re.findall('href="(.*?)">磁力連結</a>', page)[0]
    tor_url = _host + re.findall('href="(.*?)">下載檔案</a>', page)[0]

    torrent = requests.get(tor_url, headers=_header).content
    # print(torrent)
    open('./test-down.torrent', 'wb').write(torrent)

    return magnet, torrent


def main():
    get_magnet_torrent(urls, head)


if __name__ == '__main__':
    # url3 = 'http://q1.0e8c2c0f.pw/pw/html_data/3/1911/4440224.html'
    urls = 'http://www1.downsx.pw//torrent/C028FE7E36AC3EEA6177C80EAF011D357FB66076'
    main()
